package com.livesource.client.web.sourceCode.edit;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.livesource.client.LiveSourceGlobalVariables;
import com.livesource.client.model.entry.ProjectClass;
import com.livesource.client.webservices.subversion.RequestSaveClassDescription;





/** 
 * 
 * 
 * @UserInterface 
 */
public class ButtonSave extends Button {

	public ButtonSave(final ProjectClass classFile) {

		this.setText("Save");

		this.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				ProjectClass classFileUpdated = getClassFile(classFile);

				RequestSaveClassDescription.sendPostRequest(
						LiveSourceGlobalVariables.currentProject,
						classFileUpdated.toString(), classFileUpdated);
			}
		});
	}

	private ProjectClass getClassFile(ProjectClass classFile) {

		String classStatus = FeatureEdition.classStatusList
				.getValue(FeatureEdition.classStatusList.getSelectedIndex());

		if (classStatus.length() == 0) {

			classStatus = null;
		}

		classFile.setStatus(classStatus);

		String classType = FeatureEdition.classTypeList
				.getValue(FeatureEdition.classTypeList.getSelectedIndex());

		if (classType.length() == 0) {

			classType = null;
		}

		classFile.setFeatureType(classType);

		classFile.setFeatureDescription(FeatureEdition.classDescription
				.getValue());

		return classFile;
	}
}
